#The following code doesn't always work as expected and might fail migrating
#however, I'm not going to change it, as to not break databases of versions between
#this one, and the revised default event generation migration
#
#I never edit migrations after they have been committed
#if necessary, I make fix mistakes in new migrations
#
#If the following migration fails, you can skip it by running
#UPDATE schema_info SET version = 18;
#on the sql
#
# ~Coneko
class SetDefaultEvents < ActiveRecord::Migration
  def self.up
    old_events = Event.find(:all)
    base_event = Event.create(:name => "Default", :calculation_params => {}, :conversion_params => {:ratio => 1})
    old_events.each do |old_event|
      base_event.children << old_event
    end
    base_event.save
  end

  def self.down
    base_event = Event.find_by_parent_id(nil)
    base_event.destroy
  end
end
